package com.bm.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bm.common.dto.AddAllyIDDto;
import com.bm.common.util.Rutils;
import com.bm.common.vo.R;
import com.bm.server.dao.JoinAllyDao;
import com.bm.server.entity.AddAlly;
import com.bm.server.entity.Ally;
import com.bm.server.entity.AllyMid;
import com.bm.server.service.intf.JoinAllyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static org.bouncycastle.asn1.x500.style.RFC4519Style.uid;

/**
 * Hey man，take your time！
 *
 * @Author: 李松洋
 * @Description:代码永不报错，工资永在上涨！！！
 * @Date: Create in 10:20 2022/7/23
 */
@Service
public class JoinAllyServiceImpl implements JoinAllyService {
    @Resource
    private JoinAllyDao dao;
//加入联盟
    @Override
    public R one(int allyid, Long uid) {
        if(uid!=null&&allyid>0){
            if (dao.query(allyid).getNum()<=200){
                AddAllyIDDto one = dao.one(allyid,uid);
                if(one==null){
                      if (dao.insert(new AddAlly(uid,allyid))>0){
                          return Rutils.ok("加入成功");
                      }
                  }else {
                    return Rutils.fail("请勿重复加入");
                }
            }else {
                return Rutils.fail("人数已满，去别人家看看吧");
            }
            }
        
        return Rutils.fail("参数错误");
    }
//查询人数
    @Override
    public R query(int allyid) {
        if (allyid>0){
            return Rutils.ok(dao.query(allyid));
        }
        return Rutils.fail("参数有误");
    }
}
